//
//  XHSellCouponsViewController.m
//  umibus
//
//  Created by 冷山 on 16/6/18.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHSellCouponsViewController.h"
#import "XHTabBarController.h"

#import "XHCouponsCell.h"
#import "XHLabelTextFieldCell.h"
#import "XHToConfirmWithdrawalCell.h"

#import "Services.h"

#import "AppDelegate.h"


#define kPriceTextFieldTag 10

@interface XHSellCouponsViewController ()<XHToConfirmWithdrawalCellDelegate>
@property (weak, nonatomic) IBOutlet UITableView *ui_tableView;
@property (strong, nonatomic) NSString * price;

@end

@implementation XHSellCouponsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.ui_tableView registerNib:[UINib nibWithNibName:@"XHCouponsCell" bundle:nil] forCellReuseIdentifier:XHCouponsCellIdentifier];
    [self.ui_tableView registerNib:[UINib nibWithNibName:@"XHLabelTextFieldCell" bundle:nil] forCellReuseIdentifier:XHLabelTextFieldCellIdentifier];
    [self.ui_tableView registerNib:[UINib nibWithNibName:@"XHToConfirmWithdrawalCell" bundle:nil] forCellReuseIdentifier:XHToConfirmWithdrawalCellIdentifier];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSUInteger rows=0;
    if (section==0)
    {
        rows=1;
    }
    else if (section==1)
    {
        rows=2;
    }
    return rows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    if (indexPath.section==0)
    {
        cell = [self couponsCell:indexPath];
    }
    else if (indexPath.section==1)
    {
        if (indexPath.row==0)
        {
            cell = [self sellPrice];
        }
        else if (indexPath.row==1)
        {
            cell = [self toConfirmWithdrawalCell];
        }
    }
    
    return cell;
}

- (XHCouponsCell*)couponsCell:(NSIndexPath*)indexPath
{
    XHCouponsCell * cell = [self.ui_tableView dequeueReusableCellWithIdentifier:XHCouponsCellIdentifier];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.ui_useButton.hidden = YES;
    cell.ui_sellButton.hidden = YES;
    cell.ui_examplesButton.hidden = YES;
    cell.ui_xu.hidden = YES;
    cell.backgroundColor = [UIColor whiteColor];
    cell.ui_couponsContent.text = [NSString stringWithFormat:@"满%@元可用",self.couponsDic[@"minOrderAmount"]];
    if([self.couponsDic[@"couponType"]isEqualToString:@"VOUCHER_TICKET"])
    {
        //代金券
        cell.ui_discountView.hidden = YES;
        cell.ui_leftlabel.text = @"￥";
        cell.ui_leftlabel.font = [UIFont systemFontOfSize:25];
        cell.ui_rightLabel.font = [UIFont systemFontOfSize:50];
        NSString * money = [NSString stringWithFormat:@"%.2f",[self.couponsDic[@"couponValue"] doubleValue]];
        NSString * lastOne = [money substringWithRange:NSMakeRange(money.length-1,1)];
        NSString * lastTwo = [money substringWithRange:NSMakeRange(money.length-2,1)];
        if ([lastOne doubleValue]==0&&
            [lastTwo doubleValue]==0)
        {
            cell.ui_rightLabel.text = [NSString stringWithFormat:@"%@",self.couponsDic[@"couponValue"]];
        }
        else if ([lastOne doubleValue]==0&&
                 [lastTwo doubleValue]!=0)
        {
            cell.ui_rightLabel.text = [NSString stringWithFormat:@"%.1f",[self.couponsDic[@"couponValue"] doubleValue]];
        }
        else if ([lastOne doubleValue]!=0&&
                 [lastTwo doubleValue]!=0)
        {
            cell.ui_rightLabel.text = [NSString stringWithFormat:@"%.2f",[self.couponsDic[@"couponValue"] doubleValue]];
        }
        NSString * startTime = [[NSDate dateWithString:self.couponsDic[@"startTime"]] stringSlashWithFormatter];
        NSString * endTime = [[NSDate dateWithString:self.couponsDic[@"endTime"]] stringSlashWithFormatter];
        cell.ui_useTime.text = [NSString stringWithFormat:@"%@ - %@",startTime,endTime];
        if ([self.couponsDic[@"operatorCode"]isEqualToString:@"10086"])
        {
            if([self.couponsDic[@"couponStatus"]isEqualToString:@"USED"]||
               [self.couponsDic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-移动话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-移动智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_yidong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-移动话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-移动智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量屯包";
                }
            }
        }
        else if ([self.couponsDic[@"operatorCode"]isEqualToString:@"10010"])
        {
            if([self.couponsDic[@"couponStatus"]isEqualToString:@"USED"]||
               [self.couponsDic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-联通话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-联通智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_liantong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#E45252"];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-联通话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-联通智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量屯包";
                }
            }
        }
        else if ([self.couponsDic[@"operatorCode"]isEqualToString:@"10000"])
        {
            if([self.couponsDic[@"couponStatus"]isEqualToString:@"USED"]||
               [self.couponsDic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-电信话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-电信智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_dianxin"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-电信话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-电信智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量屯包";
                }
            }
        }
    }
    else if ([self.couponsDic[@"couponType"]isEqualToString:@"DISCOUNT_TICKET"])
    {
        //折扣
        cell.ui_discountView.hidden = NO;
        NSString * str = [NSString stringWithFormat:@"%.1f",[self.couponsDic[@"couponValue"] doubleValue]];
        NSString * lastOne = [str substringFromIndex:str.length-1];
        if ([lastOne isEqualToString:@"0"])
        {
            cell.ui_zhe.text = [NSString stringWithFormat:@"%@",self.couponsDic[@"couponValue"]];
        }
        else
        {
            cell.ui_zhe.text = [NSString stringWithFormat:@"%@",str];
        }

        NSString * startTime = [[NSDate dateWithString:self.couponsDic[@"startTime"]] stringSlashWithFormatter];
        NSString * endTime = [[NSDate dateWithString:self.couponsDic[@"endTime"]] stringSlashWithFormatter];
        cell.ui_useTime.text = [NSString stringWithFormat:@"%@ - %@",startTime,endTime];
        if ([self.couponsDic[@"operatorCode"]isEqualToString:@"10086"])
        {
            if([self.couponsDic[@"couponStatus"]isEqualToString:@"USED"]||
               [self.couponsDic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_yidong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量屯包";
                }
            }
        }
        else if ([self.couponsDic[@"operatorCode"]isEqualToString:@"10010"])
        {
            if([self.couponsDic[@"couponStatus"]isEqualToString:@"USED"]||
               [self.couponsDic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_liantong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#E45252"];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量屯包";
                }
            }
        }
        else if ([self.couponsDic[@"operatorCode"]isEqualToString:@"10000"])
        {
            if([self.couponsDic[@"couponStatus"]isEqualToString:@"USED"]||
               [self.couponsDic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_dianxin"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                if ([self.couponsDic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信话费直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信智能交费";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量直充";
                }
                else if ([self.couponsDic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量屯包";
                }
            }
        }
    }

    return cell;
}

-(XHLabelTextFieldCell *)sellPrice
{
    XHLabelTextFieldCell * cell = [self.ui_tableView dequeueReusableCellWithIdentifier:XHLabelTextFieldCellIdentifier];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.ui_titleLabel.text = @"出售价格";
    cell.ui_textLabel.hidden = NO;
    cell.ui_textField.placeholder = @"";
    cell.ui_textLabel.text = [NSString stringWithFormat:@"请输入出售积分值(优米指导价%@积分)",self.couponsDic[@"officalPrice"]];
    cell.ui_textField.tag = kPriceTextFieldTag;
    cell.ui_textField.keyboardType = UIKeyboardTypeNumberPad;
    
    return cell;
}

- (XHToConfirmWithdrawalCell*)toConfirmWithdrawalCell
{
    XHToConfirmWithdrawalCell * cell = [self.ui_tableView dequeueReusableCellWithIdentifier:XHToConfirmWithdrawalCellIdentifier];
    cell.delegate = self;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell.ui_withdrawalRulesBtn setTitle:@"优惠券出售后，请在积分详情中查看对应积分" forState:UIControlStateNormal];
    [cell.ui_withdrawalBtn setTitle:@"发布" forState:UIControlStateNormal];
    if ([NSString checkNullString:self.price])
    {
        cell.ui_withdrawalBtn.backgroundColor = [ColorManager colorWithHexString:@"#000000" alpha:0.25];
        cell.ui_withdrawalBtn.enabled = NO;
    }
    else
    {
        cell.ui_withdrawalBtn.backgroundColor = [ColorManager colorWithHexString:@"#5997A4"];
        cell.ui_withdrawalBtn.enabled = YES;
    }

    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height=0;
    if (indexPath.section==0)
    {
        height=110;
    }
    else if (indexPath.section==1)
    {
        if (indexPath.row==0)
        {
            height=50;
        }
        else if (indexPath.row==1)
        {
            height=110;
        }
    }
    return height;
}

- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat height = 10;

    return height;
}

- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    CGFloat height = 0.1;
    return height;
}

#pragma mark - TextFieldNotification

- (void)textFieldTextDidChangeNotification:(NSNotification *)notif
{
    UITextField * textField = (UITextField *)[notif object];
    NSIndexPath *indexPath1=[NSIndexPath indexPathForRow:0 inSection:1];
    XHLabelTextFieldCell * cell = [self.ui_tableView cellForRowAtIndexPath:indexPath1];
    switch (textField.tag)
    {
        case kPriceTextFieldTag:
            self.price = textField.text;
            if ([NSString checkNullString:textField.text])
            {
                cell.ui_textLabel.hidden = NO;
            }
            else
            {
                cell.ui_textLabel.hidden = YES;
            }
            break;
    }
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:1 inSection:1];
    [self.ui_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma - mark XHToConfirmWithdrawalCellDelegate 

- (void)withdrawalAction:(UIButton*)btn
{
    if ([NSString checkNullString:self.price])
    {
        [PromptAction showInfoPrompt:@"请输入出售价格"];
    }
    else
    {
        [ServiceManager putawayCouponsWithCode:self.couponsDic[@"sequenceNBR"] salesPrice:self.price success:^(NSDictionary *data) {
            AppDelegate * delegate = [UIApplication sharedApplication].delegate;
            [delegate.tabBarController publishCoupons];
            [self.navigationController popToRootViewControllerAnimated:YES];
        } failure:^(NSDictionary *data) {
            
        }];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
